<?php


/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');

class HelpDeskHelperStatus 
{
	/**
	 * 
	 * @param $id
	 * @return unknown_type
	 */
	function getImage( $id, $by='id' )
	{
		$type = HelpDeskHelperStatus::getType( $id, $by );
		$title = HelpDeskText::_( $type->title );
		$src = $type->img;
		$tmpl = "<img src='{$src}' alt='{$title}' title='{$title}' name='{$title}'>";
		return $tmpl;
	}
	
	/**
	 * 
	 * @param $id
	 * @param $by
	 * @return unknown_type
	 */
	function getType( $id, $by='id' ) 
	{
		$return = new HelpDeskObject();
		$return->id		= '';
		$return->name	= 'undefined';
		$return->title	= "Undefined";
		
		$types = HelpDeskHelperStatus::getTypes();
		for ($i=0; $i<count($types); $i++) 
		{
			$type = $types[$i];
			switch( $by )
			{
				case "name":
					if ($type->name == $id) {
						$return = $type;
						break 2;
					}
				  break;
				case "id":
				default:
					if ($type->id == $id) {
						$return = $type;
						break 2;
					}
				  break;
			}
		}
		
		return $return;
	}
	
	/**
	 * 
	 * @return unknown_type
	 */
	function getTypes()
	{
		$types = array();
			$object = new HelpDeskObject();
			$object->id 	= '0';
			$object->name 	= 'open';
			$object->title 	= 'Open Tickets';
			$object->status	= 'Pending Resolution';
			$object->img	= HelpDeskUrl::root()."/components/com_helpdesk/images/status/pending.png";
		$types[] = $object;
			$object = new HelpDeskObject();
			$object->id 	= '1';
			$object->name 	= 'followup'; 
			$object->title 	= 'For Followup';
			$object->status	= 'Pending Resolution';
			$object->img	= HelpDeskUrl::root()."/components/com_helpdesk/images/status/pending.png";
		$types[] = $object;
			$object = new HelpDeskObject();
			$object->id 	= '3';
			$object->name 	= 'feedback';
			$object->title 	= 'Requiring Feedback';
			$object->status	= 'Requires Feedback';
			$object->img	= HelpDeskUrl::root()."/components/com_helpdesk/images/status/requirefeedback.png";
		$types[] = $object;
			$object = new HelpDeskObject();
			$object->id 	= '2';
			$object->name 	= 'closed'; 
			$object->title 	= 'Closed Tickets';
			$object->status	= 'Closed';
			$object->img	= HelpDeskUrl::root()."/components/com_helpdesk/images/status/completed.gif";
		$types[] = $object;
			$object = new HelpDeskObject();
			$object->id 	= '-1';
			$object->name 	= 'all'; 
			$object->title 	= 'All Tickets';
		$types[] = $object;
					
		return $types;
	}
	
	/**
	 * Creates a List
	 * @return array Array of objects containing the data from the database
	 */
	function getSelectListTypes( $exception='' ) 
	{
		$done = array();
		static $_selectListTypes;
		
		if (empty($_selectListTypes)) {
			$types[] = mosHTML::makeOption( '', '- '.HelpDeskText::_( 'Select from List' ).' -' );
			$data = HelpDeskHelperStatus::getTypes();
			if ($data) {
				foreach ($data as $d) {
					$types[] = mosHTML::makeOption( $d->name, HelpDeskText::_( $d->title ) );
				}
			}
		
			$_selectListTypes = $types;
		
		}

		return $_selectListTypes;
	}

	/**
	 *
	 * @return
	 * @param $field Object
	 * @param $default Object[optional]
	 * @param $options Object[optional]
	 */
	function getSelectList( $field, $default='', $options='' )
	{
		return mosHTML::selectList( HelpDeskHelperStatus::getSelectListTypes(), $field, $options, 'value','text', $default);
	}
}